# -*- coding: utf-8 -*-
"""
Created on Mon Apr  8 10:55:17 2019

@author: Farman-X220
"""
import os


def enum_files(path='.', file_ext='tif'):
    '''
    Enum files by file_ext in path given.
    tif file enummed by default.
    '''
    print("Enum files at %s with extension [.%s]."%(path, file_ext))
    abs_path = os.path.abspath(path)
    print(abs_path)
    files = os.listdir(abs_path)
    files_found = []
    
    for f in files:
        dot_pos = f.rfind('.')

        if dot_pos > -1 and f[dot_pos+1:].lower() == file_ext:
            files_found.append(path + '\\' + f)
            
    files_found.sort()
    return files_found


def enum_files_deep(path='.', file_ext='tif'):
    '''
    Enum files by file_ext in path given and its subpaths.
    HDF file enummed by default.
    '''
    print("Enum files at %s with extension [.%s]."%(path, file_ext))
    abs_path = os.path.abspath(path)
    files = os.listdir(abs_path)
    files_found = []
    
    for f in files:        
        if os.path.isdir(f):
            files_found += enum_files_deep(os.path.abspath(f))
        else:
            dot_pos = f.rfind('.')
            
            if dot_pos > -1 and f[dot_pos+1:].lower() == file_ext:
                files_found.append(path + '\\' + f)
    
    files_found.sort()
    return files_found


if __name__ == '__main__':
    files = enum_files_deep(r'G:\Shenmu20191014\权重分配\地表温度\归一化')
    files = enum_files(r'G:\Shenmu20191014\权重分配\地表温度\归一化')

    for f in files:
        print(f)
